﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using lbl.WcfServices.Contracts;

namespace lbl.WcfServices.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            InstanceContext instanceContext = new InstanceContext(new callback());
            using(DuplexChannelFactory<ICalculator> ChannelFactory=new DuplexChannelFactory<ICalculator>(instanceContext,"CalculatorService") )
            {
                ICalculator proxy = ChannelFactory.CreateChannel();
                using(proxy as IDisposable)
                {
                    proxy.Add(1, 2);
                    Console.Read();
                }
            }
            //using (ChannelFactory<ICalculator> channelFactor = new ChannelFactory<ICalculator>(new WSHttpBinding(), "http://127.0.0.1:9999/calculatorservice"))
            //{
            //    ICalculator proxy = channelFactor.CreateChannel();
            //    using (proxy as IDisposable)
            //    {
            //        Console.WriteLine("I:x+y={2} when x={0} and y={1}", 1, 2, proxy.Add(1, 2));
            //        Console.WriteLine("I:x-y={2} when x={0} and y={1}", 1, 2, proxy.Subtract(1, 2));
            //        Console.WriteLine("I:x*y={2} when x={0} and y={1}", 1, 2, proxy.Multiply(1, 2));
            //        Console.WriteLine("I:x/y={2} when x={0} and y={1}", 1, 2, proxy.Divide(1, 2));
            //    }
            //}

            //using (ChannelFactory<ICalculator> channelFactor = new ChannelFactory<ICalculator>("calculatorservice"))
            //{
            //    ICalculator proxy = channelFactor.CreateChannel();
            //    using (proxy as IDisposable)
            //    {
            //        Console.WriteLine("s:x+y={2} when x={0} and y={1}", 1, 2, proxy.Add(1, 2));
            //        Console.WriteLine("s:x-y={2} when x={0} and y={1}", 1, 2, proxy.Subtract(1, 2));
            //        Console.WriteLine("s:x*y={2} when x={0} and y={1}", 1, 2, proxy.Multiply(1, 2));
            //        Console.WriteLine("s:x/y={2} when x={0} and y={1}", 1, 2, proxy.Divide(1, 2));
            //    }
            //}

            //using (CalculatorServiceClient proxy = new CalculatorServiceClient())
            //{
            //    Console.WriteLine("x+y={2} when x={0} and y={1}", 1, 2, proxy.Add(1, 2));
            //    Console.WriteLine("x-y={2} when x={0} and y={1}", 1, 2, proxy.Subtract(1, 2));
            //    Console.WriteLine("x*y={2} when x={0} and y={1}", 1, 2, proxy.Multiply(1, 2));
            //    Console.WriteLine("x/y={2} when x={0} and y={1}", 1, 2, proxy.Divide(1, 2));

            //    Console.Read();
            //}
        }
    }
}
